<template>
  <el-dialog
    title="供应商列表"
    :visible.sync="show"
    width="900px"
    center
    append-to-body
  >
    <div class="search-box">
      <el-form label-width="100px" :inline="true">
        <el-form-item label="供应商名称">
          <el-input v-model="name" />
        </el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="search()">查询</el-button>
        <el-button type="warning" icon="el-icon-refresh" @click="reset()">重置</el-button>
      </el-form>
    </div>
    <div class="content-box">
      <com-table
        v-model="selectNode"
        highlight-current-row
        :data="dataList"
        :columns="columns"
        :total="total"
        @pageChange="pageChange"
      >
        <template v-slot:createTime="{row: {createTime}}">
          {{ dateFormat(createTime) }}
        </template>
        <template v-slot:options="{row}">
          <el-button type="success" size="mini" @click="getCheckList(row)">引入</el-button>
        </template>
      </com-table>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="show = false">取 消</el-button>
      <el-button type="primary" :loading="searching" @click="confirm">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { getSupplierFinishInfoList } from '@/api/bigManage'
import moment from 'moment'
import { getDictName } from '@/utils/comm'
import { projectInfoProjStatus, projectInfoProjType, projectInfoProjMode } from '@/utils/dicData'
export default {
  name: 'ProjectList',
  components: {

  },
  props: {
    showModal: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      projectInfoProjStatus,
      projectInfoProjType,
      projectInfoProjMode,
      getDictName,
      visible: false,
      name: '',
      total: 0,
      pageParams: {
        pageNum: 1,
        pageSize: 10
      },
      selectNode: null,
      searching: false,
      dataList: [], // 列表
      columns: [
        {
          label: '供应商编号',
          prop: 'number'
        },
        {
          label: '供应商名称',
          prop: 'name'
        },
        {
          label: '省份',
          prop: 'province'
        },
        {
          label: '城市',
          prop: 'city'
        }
      ]
    }
  },
  computed: {
    show: {
      get() {
        return this.showModal
      },
      set(val) {
        this.$emit('update:showModal', val)
      }
    }
  },
  watch: {
    showModal: {
      handler(newData) {
        if (newData) {
          this.getDataList()
        }
      },
      deep: true,
      immediate: true
    }
  },
  mounted() {

  },
  methods: {
    dateFormat(data) {
      if (data) {
        return moment(data).format('YYYY-MM-DD')
      } else {
        return ''
      }
    },
    confirm() {
      if (this.selectNode) {
        this.getCheckList(this.selectNode)
      } else {
        this.show = false
      }
    },
    // 根据id获取 项目清单列表
    getCheckList(obj) {
      this.$emit('getSelectedRows', obj)
      this.show = false
    },
    // confirm(obj) {
    //   this.show = false
    //   this.$emit('getSelectedRows', obj)
    // },
    pageChange(data) {
      this.pageParams = data
      this.getDataList()
    },
    getSelectedRows(data) {

    },
    getDataList() {
      const params = {
        ...this.pageParams,
        name: this.name
      }
      getSupplierFinishInfoList(params).then(res => {
        const { data, total } = res.data || {}
        if (data) {
          this.dataList = data
          this.total = total - 0
        }
      })
    },
    search() {
      this.getDataList()
    },
    reset() {
      this.name = ''
      this.getDataList()
    }
  }
}
</script>

<style lang="scss" scoped>
.com-form-title{
  font-size: 14px;
  font-weight: bold;
  line-height: 35px;
  color: #409EFF;
  border-bottom: 1px solid #dedede;
  margin-bottom: 6px;
}
::v-deep .content-box{
  overflow: hidden;
}
</style>
